/**
 * @author AdinZ
 * @date 2022/12/11 23:00
 *
 */
const state = {
    show: false,
    callbacks: []
}
const mutations = {
    setShow: (state, show) => {
        state.show = show;
    },
    addCallback: (state, cb) => {
        state.callbacks.push(cb)
    },
    clearCallback: (state) => {
        state.callbacks = []
    }
}
const actions = {
    show({commit}, cb) {
        commit('addCallback', cb)
        commit('setShow', true)
    },
    hide({commit}) {
        commit('setShow', false)
        commit('clearCallback')
    },
    execute(context, data) {
        context.state.callbacks.forEach(e => e(data))
        context.dispatch('hide')
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}